package com.wmm.jinhong;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.Button;
import android.widget.TextView;

import java.util.List;

public class SCRKAdapter extends BaseAdapter {
    private Context context;
    private List<GangPingBean> list;
    private LayoutInflater inflater;
    public SCRKAdapter(Context context,List<GangPingBean> list){
        this.context=context;
        this.list=list;
        inflater=LayoutInflater.from(context);
    }
    @Override
    public int getCount() {
        return list.size();
    }

    @Override
    public Object getItem(int position) {
        return list.get(position);
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(final int position, View convertView, ViewGroup parent) {
        ViewHoder viewHoder=null;
        if(convertView==null){
            viewHoder=new ViewHoder();
            convertView=inflater.inflate(R.layout.item_scrk,null);
            viewHoder.textView=convertView.findViewById(R.id.txt_gp_code);
            viewHoder.textView2=convertView.findViewById(R.id.txt_gp_jz);
            viewHoder.textView3=convertView.findViewById(R.id.txt_gp_gg);
            viewHoder.textView4=convertView.findViewById(R.id.txt_is_bm);
            viewHoder.textView4=convertView.findViewById(R.id.txt_is_bm);
            viewHoder.button=convertView.findViewById(R.id.btn_del);
            convertView.setTag(viewHoder);
        }else{
            viewHoder=(ViewHoder) convertView.getTag();
        }
        final GangPingBean bean=list.get(position);
        viewHoder.textView.setText(bean.getGangPingHao());
        viewHoder.textView2.setText(bean.getInvName());
        viewHoder.textView3.setText(bean.getcInvStd());
        viewHoder.textView4.setText(bean.getcInvCode());
        viewHoder.button.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                list.remove(position);
                notifyDataSetChanged();
            }
        });
        return convertView;
    }
    public List<GangPingBean> getLists(){
        return list;
    }
    class ViewHoder{
        TextView textView;
        TextView textView2;
        TextView textView3;
        TextView textView4;
        Button button;
    }
}
